<?php

	// TITLE: Donation_type AUTO MODEL
	// FILE: scaffolding/model/donation_type.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createDonationType = function($con, $donationType) {
		$sql = 'INSERT INTO donation_type (type_id, title, code, description) VALUES (';
		$sql .= $donation_type->getTypeId() . ', ';
		$sql .= $donation_type->getTitle() . ', ';
		$sql .= $donation_type->getCode() . ', ';
		$sql .= $donation_type->getDescription() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readDonationType = function($con, $id) {
		$sql = 'SELECT * FROM donation_type WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$donationType = new DonationType();
			$donationType->setTypeId($dbio->select($readType(result[0])));
			$donationType->setTitle(result[1]);
			$donationType->setCode(result[2]);
			$donationType->setDescription(result[3]);
		} else {
			$donationType = false;
		}
		return $donationType;
	};

	$updateDonationType = function($con, $donationType) {
		$sql = 'UPDATE donation_type SET ';
		$sql .= 'type_id = ' . $donation_type->getTypeId() . ', ';
		$sql .= 'title = ' . $donation_type->getTitle() . ', ';
		$sql .= 'code = ' . $donation_type->getCode() . ', ';
		$sql .= 'description = ' . $donation_type->getDescription() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteDonationType = function($con, $id) {
		$sql = 'DELETE FROM donation_type WHERE type_id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listDonationType = function($con) {
		$sql = 'SELECT * FROM donation_type';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$donationTypes = array();
			while ($result = mysqli_fetch_array($results)) {
				$donationType = new DonationType();
				$donationType->setTypeId($dbio->select($readType(result[0])));
				$donationType->setTitle(result[1]);
				$donationType->setCode(result[2]);
				$donationType->setDescription(result[3]);
				$donationTypes[] = donationType;
			}// end while
		} else {
			$donationTypes = false;
		}
		return $donationTypes;
	};

